﻿using LiJu.Db;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LiJu.Product.View
{
    public partial class CopyProdcut : Form
    {
        public Action<string, string> CopyProductAction = null;
        public CopyProdcut()
        {
            InitializeComponent();
        }

        private void btn_AddProduct_Click(object sender, EventArgs e)
        {
            string productName = txt_ProductName.Text.Trim();
            string productSN = txt_ProductSN.Text.Trim();
            if ( string.IsNullOrEmpty(productName))
            {
                MessageBox.Show("请输入新的产品名称");
                return;
            }
            if (string.IsNullOrEmpty(productSN))
            {
                MessageBox.Show("请输入新的产品名称");
                return;
            }
            var product = ProductDbHelper.GetProductByCode(txt_ProductSN.Text.Trim());
            if (product != null)
            {
                MessageBox.Show("产品条码已存在");
                return;
            }
            CopyProductAction?.Invoke(productName, productSN);
            this.DialogResult = DialogResult.OK;
        }
    }
}
